#include <iostream>

#include "For.hpp"

#include "Expression.hpp"
#include "ExpressionValue.hpp"

For::For(Instruction* _initialisation, Expression* _condition, Instruction* _increment, Instruction* _codeBoucle)
{
    initialisation = _initialisation;
    condition = _condition;
    increment = _increment;
    codeBoucle = _codeBoucle;
}

void For::execute()
{
  initialisation->execute();
  condition->compute();
    
  while( getBoolean(condition->getValue()) == true )
  {
    codeBoucle->execute();
    increment->execute();
  }
}

void For::display(const unsigned int shift) const
{
    std::cout << "for (";
    initialisation->display();
    std::cout << ", ";
    condition->display();
    std::cout << ", ";
    increment->display();
    std::cout << ")\n";
    std::cout << "{\n";
        std::cout << "\t";
        codeBoucle->display();
        std::cout << "\n";
    std::cout << "}\n";
}

For::~For(){}
